package cn.neusoft.yuejian307.Fragment.ortherfragmnet;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import java.util.List;

import cn.neusoft.yuejian307.R;
import cn.neusoft.yuejian307.adapter.NewsAdapter;
import cn.neusoft.yuejian307.bean.NewBean;
import cn.neusoft.yuejian307.listener.UserListener;
import cn.neusoft.yuejian307.model.UserModel;

import static cn.neusoft.yuejian307.GloableVirable.USERID;
import static cn.neusoft.yuejian307.model.UserModel.SEND_NEWS_FLAG;



public class FragmentMasterAnserQuestion  extends Fragment implements UserListener<List<NewBean>>{
                private View view ;
                private EditText content;
                private Button commit;
                private RecyclerView recyclerView_video;
                private Handler handler = new Handler();
                Runnable runnable = new Runnable() {
                    public void run() {
                        this.update();
                        handler.postDelayed(this, 500);// 间隔1秒
                    }
                    void update() {
                        if (SEND_NEWS_FLAG == true){
                content.setText("");
                SEND_NEWS_FLAG = false;
            }
        }
    };
    @Override
    public View onCreateView(LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.fragment_question_to_master, null) ;
        UserModel userModel = new UserModel();
        userModel.newsData(this,1);
        init();
        handler.postDelayed(runnable, 100*1);
        return view ;
    }
    private void init(){
        recyclerView_video = (RecyclerView)view.findViewById(R.id.recyclerView_video);
        recyclerView_video.setLayoutManager(new LinearLayoutManager(getActivity()));
        content = (EditText)view.findViewById(R.id.content);
        commit = (Button)view.findViewById(R.id.commit);
        commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String mContent = content.getText().toString();
                UserModel userModel = new UserModel();
                userModel.addNewsData(1,USERID,mContent,getActivity());//发评论
            }
        });

    }

    @Override
    public void onResponse(List<NewBean> newBeen) {
        NewsAdapter adapter = new NewsAdapter(getActivity(),newBeen);
        recyclerView_video.setAdapter(adapter);
    }

    @Override
    public void onFail(String msg) {

    }
}
